package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.exartisan.thanhdoanhn.R;
import com.loopj.android.image.SmartImageView;


public class ImagePagerAdapter extends PagerAdapter {
	Context context;
	ArrayList<String> imgURLs;
	LayoutInflater inflater;


	public ImagePagerAdapter(Context context, ArrayList<String> imgURLs) {
		super();
		this.context = context;
		this.imgURLs = imgURLs;
	}

	@Override
	public int getCount() {
		return imgURLs.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == ((RelativeLayout) object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		// Declare Variables
		SmartImageView smartImg;

		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View itemView = inflater.inflate(R.layout.viewpager_item, container,
				false);

		// viewpager_item.xml
		 smartImg = (SmartImageView) itemView.findViewById(R.id.image);
		 
		// Set data
		smartImg.setImageUrl(imgURLs.get(position));
		itemView.setId(position);

		// Add viewpager_item.xml to ViewPager
		((ViewPager) container).addView(itemView);

		return itemView;

	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		// TODO Auto-generated method stub
		((ViewPager) container).removeView((RelativeLayout) object);
	}

}
